package models

import (
	"cloudops/src/common"
	"cloudops/src/config"
	"fmt"
	"go.uber.org/zap"
)

const (
	ApiTitleAllRead       = "所有-读操作"
	ApiTitleK8sAdminWrite = "k8s管理员-写操作"
	ApiTitleK8sAppWrite   = "k8s应用-写操作"
)

var (
	menuFathers = []*Menu{
		{
			Name:      "System",
			Title:     "系统管理",
			Icon:      "ion:settings-outline",
			Type:      "0",
			Show:      "1",
			OrderNo:   1,
			Component: "LAYOUT",
			Redirect:  "/system/account",
			Path:      "/system",
		},
		// 前端权限管理默认 不开，自己开
		{
			Name:      "Permission",
			Title:     "权限管理",
			Icon:      "ion:layers-outline",
			Type:      "0",
			Show:      "0",
			OrderNo:   2,
			Component: "LAYOUT",
			Path:      "/permission",
			Redirect:  "/permission/front/page",
		},
		{
			Name:      "ServiceTree",
			Title:     "服务树与cmdb",
			Icon:      "ion:layers-outline",
			Type:      "0",
			Show:      "1",
			OrderNo:   3,
			Component: "LAYOUT",
			Path:      "/serviceTree",
			Redirect:  "/serviceTree/serviceTree/index",
		},
		{
			Name:      "WorkOrder",
			Title:     "工单系统",
			Icon:      "ion:git-compare-outline",
			Type:      "0",
			Show:      "1",
			OrderNo:   4,
			Component: "LAYOUT",
			Path:      "/workOrder",
			Redirect:  "/workOrder/process/index",
		},

		{
			Name:      "JobExec",
			Title:     "任务执行中心",
			Icon:      "ion:git-compare-outline",
			Type:      "0",
			Show:      "1",
			OrderNo:   5,
			Component: "LAYOUT",
			Path:      "/jobExec",
			Redirect:  "/jobExec/task/index",
		},

		{
			Name:      "PrometheusMonitor",
			Title:     "prometheus监控",
			Icon:      "ion:tv-outline",
			Type:      "0",
			Show:      "1",
			OrderNo:   6,
			Component: "LAYOUT",
			Path:      "/monitor",
			Redirect:  "/monitor/scrape/index",
		},

		{
			Name:      "K8sAdmins",
			Title:     "[管理员]k8s多集群管理",
			Icon:      "ant-design:cloud-server-outlined",
			Type:      "0",
			Show:      "1",
			OrderNo:   7,
			Component: "LAYOUT",
			Path:      "/k8s",
			Redirect:  "/k8s/cluster/index",
		},

		{
			Name:      "K8sOpsManagement",
			Title:     "[运维]k8s应用管理",
			Icon:      "ant-design:dropbox-square-filled",
			Type:      "0",
			Show:      "1",
			OrderNo:   8,
			Component: "LAYOUT",
			Path:      "/k8sApplication",
			Redirect:  "/k8sApplication/project/index",
		},
		{
			Name:      "CicdManagement",
			Title:     "cicd管理",
			Icon:      "ant-design:printer-filled",
			Type:      "0",
			Show:      "1",
			OrderNo:   9,
			Component: "LAYOUT",
			Path:      "/cicd",
			Redirect:  "/cicd/workorder/index",
		},
	}

	menuSystem = []*Menu{
		{
			Name:      "MenuManagement",
			Title:     "菜单管理",
			Icon:      "ant-design:account-book-filled",
			Type:      "1",
			Show:      "1",
			OrderNo:   1,
			Component: "/demo/system/menu/index",
			Pid:       1,
			Path:      "menu",
		},
		{
			Name:      "AccountManagement",
			Title:     "用户管理",
			Icon:      "ant-design:account-book-twotone",
			Type:      "1",
			Show:      "1",
			OrderNo:   2,
			Component: "/demo/system/account/index",
			Pid:       1,
			Path:      "account",
		},
		{
			Name:      "RoleManagement",
			Title:     "角色管理",
			Icon:      "ion:layers-outline",
			Type:      "1",
			Show:      "1",
			OrderNo:   3,
			Component: "/demo/system/role/index",
			Pid:       1,
			Path:      "role",
		},
		{
			Name:      "ChangePassword",
			Title:     "修改密码",
			Icon:      "ion:layers-outline",
			Type:      "1",
			Show:      "1",
			OrderNo:   4,
			Component: "/demo/system/password/index",
			Pid:       1,
			Path:      "changePassword",
		},

		{
			Name:      "ApiManagement",
			Title:     "api接口管理",
			Icon:      "ant-design:account-book-filled",
			Type:      "1",
			Show:      "1",
			OrderNo:   5,
			Component: "/demo/system/api/index",
			Pid:       1,
			Path:      "api",
		},
	}

	// 前端权限管理默认 不开，自己开
	menuFront = []*Menu{
		{
			Name:      "PermissionFrontDemo",
			Title:     "前端权限管理",
			Icon:      "ion:layers-outline",
			Type:      "1",
			Show:      "1",
			OrderNo:   1,
			Component: "/demo/permission/front/index",
			Pid:       2,
			Path:      "front",
		},
	}
	menuServiceTree = []*Menu{

		{
			Name:      "ServiceTreeIndex",
			Title:     "服务树",
			Icon:      "ant-design:account-book-filled",
			Type:      "1",
			Show:      "1",
			OrderNo:   1,
			Component: "/stree/stree/index",
			Pid:       3,
			Path:      "stree",
		},
		{
			Name:      "ServiceTreeIndexAsync",
			Title:     "服务树异步",
			Icon:      "ant-design:account-book-filled",
			Type:      "1",
			Show:      "1",
			OrderNo:   2,
			Component: "/stree/stree/indexAsync",
			Pid:       3,
			Path:      "streeAsync",
		},
	}

	menuWorkOrder = []*Menu{

		{
			Name:      "ProcessManagement",
			Title:     "流程管理",
			Icon:      "ant-design:account-book-filled",
			Type:      "1",
			Show:      "1",
			OrderNo:   1,
			Component: "/workorder/process/index",
			Pid:       4,
			Path:      "process",
		},
		{
			Name:      "FormDesignManagement",
			Title:     "表单设计管理",
			Icon:      "ant-design:account-book-filled",
			Type:      "1",
			Show:      "1",
			OrderNo:   3,
			Component: "/workorder/formDesign/index",
			Pid:       4,
			Path:      "formDesign",
		},

		{
			Name:      "WorkOrderTemplateManagement",
			Title:     "工单模板管理",
			Icon:      "ant-design:account-book-filled",
			Type:      "1",
			Show:      "1",
			OrderNo:   4,
			Component: "/workorder/template/index",
			Pid:       4,
			Path:      "template",
		},
		{
			Name:      "WorkOrderApply",
			Title:     "工单申请",
			Icon:      "ant-design:account-book-filled",
			Type:      "1",
			Show:      "1",
			OrderNo:   4,
			Component: "/workorder/apply/index",
			Pid:       4,
			Path:      "apply",
		},
		{
			Name:      "WorkOrderCreate",
			Title:     "工单创建",
			Icon:      "ant-design:account-book-filled",
			Type:      "1",
			Show:      "0",
			OrderNo:   4,
			Component: "/workorder/apply/create",
			Pid:       4,
			Path:      "create",
		},
		{
			Name:      "WorkOrderSearch",
			Title:     "工单查询",
			Icon:      "simple-icons:about-dot-me",
			Type:      "1",
			Show:      "1",
			OrderNo:   4,
			Component: "/workorder/apply/search",
			Pid:       4,
			Path:      "search",
		},
		{
			Name:      "WorkOrderDetail",
			Title:     "工单详情",
			Icon:      "ant-design:account-book-filled",
			Type:      "1",
			Show:      "0",
			OrderNo:   4,
			Component: "/workorder/detail/index",
			Pid:       4,
			Path:      "detail",
		},
	}

	menuJobExec = []*Menu{

		{
			Name:      "JobExecScript",
			Title:     "脚本管理",
			Icon:      "ant-design:account-book-filled",
			Type:      "1",
			Show:      "1",
			OrderNo:   4,
			Component: "/jobexec/script/index",
			Pid:       5,
			Path:      "script",
		},
		{
			Name:      "JobExecTask",
			Title:     "任务管理",
			Icon:      "ant-design:code-filled",
			Type:      "1",
			Show:      "1",
			OrderNo:   5,
			Component: "/jobexec/task/index",
			Pid:       5,
			Path:      "task",
		},

		{
			Name:      "JobExecDetail",
			Title:     "任务详情",
			Icon:      "ant-design:account-book-filled",
			Type:      "1",
			Show:      "0",
			OrderNo:   6,
			Component: "/jobexec/detail/index",
			Pid:       5,
			Path:      "detail",
		},
	}

	menuPrometheusMonitor = []*Menu{

		{
			Name:      "MonitorPool",
			Title:     "Prometheus集群管理",
			Icon:      "ant-design:undo-outlined",
			Type:      "1",
			Show:      "1",
			OrderNo:   1,
			Component: "/monitor/pool/index",
			Pid:       6,
			Path:      "pool",
		},
		{
			Name:      "MonitorScrapeJob",
			Title:     "prometheus采集job",
			Icon:      "ant-design:file-search-outlined",
			Type:      "1",
			Show:      "1",
			OrderNo:   2,
			Component: "/monitor/scrape/index",
			Pid:       6,
			Path:      "scrape",
		},

		{
			Name:      "MonitorAlertmanagerPool",
			Title:     "alertmanager集群管理",
			Icon:      "ant-design:alert-outlined",
			Type:      "1",
			Show:      "1",
			OrderNo:   3,
			Component: "/monitor/alertmanager/index",
			Pid:       6,
			Path:      "alertmanager",
		},

		{
			Name:      "MonitorOndutyGroup",
			Title:     "值班组管理",
			Icon:      "ant-design:calendar-outlined",
			Type:      "1",
			Show:      "1",
			OrderNo:   4,
			Component: "/monitor/ondutygroup/index",
			Pid:       6,
			Path:      "ondutygroup",
		},

		{
			Name:      "MonitorSendGroup",
			Title:     "发送组管理",
			Icon:      "ant-design:dingding-outlined",
			Type:      "1",
			Show:      "1",
			OrderNo:   5,
			Component: "/monitor/sendgroup/index",
			Pid:       6,
			Path:      "sendgroup",
		},

		{
			Name:      "MonitorAlertRule",
			Title:     "告警规则管理",
			Icon:      "ant-design:sisternode-outlined",
			Type:      "1",
			Show:      "1",
			OrderNo:   6,
			Component: "/monitor/alertrule/index",
			Pid:       6,
			Path:      "alertrule",
		},
		{
			Name:      "MonitorAlertEvent",
			Title:     "告警事件管理",
			Icon:      "ant-design:project-outlined",
			Type:      "1",
			Show:      "1",
			OrderNo:   7,
			Component: "/monitor/event/index",
			Pid:       6,
			Path:      "event",
		},
		{
			Name:      "MonitorRecordRule",
			Title:     "预聚合规则管理",
			Icon:      "ant-design:heat-map-outlined",
			Type:      "1",
			Show:      "1",
			OrderNo:   8,
			Component: "/monitor/recordrule/index",
			Pid:       6,
			Path:      "recordrule",
		},

		{
			Name:      "MonitorOndutyGroupPlan",
			Title:     "值班组排班",
			Icon:      "ant-design:calendar-outlined",
			Type:      "1",
			Show:      "0",
			OrderNo:   20,
			Component: "/monitor/ondutygroup/plan",
			Pid:       6,
			Path:      "ondutygroup-plan",
		},

		{
			Name:      "MonitorPrometheusMainYaml",
			Title:     "prometheus主配置查看",
			Icon:      "ant-design:undo-outlined",
			Type:      "1",
			Show:      "0",
			OrderNo:   20,
			Component: "/monitor/pool/mainYaml",
			Pid:       6,
			Path:      "mainYaml",
		},

		{
			Name:      "MonitorPrometheusAlertRuleYaml",
			Title:     "prometheus告警规则配置查看",
			Icon:      "ant-design:undo-outlined",
			Type:      "1",
			Show:      "0",
			OrderNo:   20,
			Component: "/monitor/pool/alertRuleYaml",
			Pid:       6,
			Path:      "alertRuleYaml",
		},
		{
			Name:      "MonitorPrometheusRecordRuleYaml",
			Title:     "prometheus预聚合规则配置查看",
			Icon:      "ant-design:undo-outlined",
			Type:      "1",
			Show:      "0",
			OrderNo:   20,
			Component: "/monitor/pool/recordRuleYaml",
			Pid:       6,
			Path:      "recordRuleYaml",
		},
		{
			Name:      "MonitorAlertmanagerYaml",
			Title:     "Alertmanager配置查看",
			Icon:      "ant-design:undo-outlined",
			Type:      "1",
			Show:      "0",
			OrderNo:   20,
			Component: "/monitor/alertmanager/yaml",
			Pid:       6,
			Path:      "alertManagerYaml",
		},
	}

	menuK8sClusters = []*Menu{
		{
			Name:      "K8sClustersManagement",
			Title:     "k8s集群管理",
			Icon:      "ion:layers-outline",
			Type:      "1",
			Show:      "1",
			OrderNo:   1,
			Component: "/k8s/cluster/index",
			Pid:       7,
			Path:      "cluster",
		},
		{
			Name:      "K8sNodesManagement",
			Title:     "k8s节点管理",
			Icon:      "ant-design:hdd-outlined",
			Type:      "1",
			Show:      "1",
			OrderNo:   2,
			Component: "/k8s/node/index",
			Pid:       7,
			Path:      "node",
		},
		{
			Name:      "K8sNodesDetail",
			Title:     "k8s节点管理",
			Icon:      "ant-design:insert-row-above-outlined",
			Type:      "1",
			Show:      "0",
			OrderNo:   2,
			Component: "/k8s/node/detail",
			Pid:       7,
			Path:      "nodeDetail",
		},
		{
			Name:      "K8sYamlTemplate",
			Title:     "k8s-yaml模板管理",
			Icon:      "ant-design:expand-outlined",
			Type:      "1",
			Show:      "1",
			OrderNo:   3,
			Component: "/k8s/yaml/template",
			Pid:       7,
			Path:      "yamlTemplate",
		},
		{
			Name:      "K8sYamlTask",
			Title:     "k8s-yaml任务管理",
			Icon:      "ant-design:merge-cells-outlined",
			Type:      "1",
			Show:      "1",
			OrderNo:   4,
			Component: "/k8s/yaml/task",
			Pid:       7,
			Path:      "yamlTask",
		},
		{
			Name:      "K8sPodManagement",
			Title:     "k8s-pod管理",
			Icon:      "ant-design:cluster-outlined",
			Type:      "1",
			Show:      "1",
			OrderNo:   5,
			Component: "/k8s/podAdmin/index",
			Pid:       7,
			Path:      "podList",
		},

		//{
		//	Name:      "K8sPodNormalLog",
		//	Title:     "k8s-pod非tail-log",
		//	Icon:      "ant-design:shop-two-tone",
		//	Type:      "1",
		//	Show:      "0",
		//	OrderNo:   5,
		//	Component: "/k8s/podAdmin/normalLog",
		//	Pid:       7,
		//	Path:      "podNormalLog",
		//},
		//
		//{
		//	Name:      "K8sPodTailLog",
		//	Title:     "k8s-pod-ws-tail-log",
		//	Icon:      "ant-design:shop-two-tone",
		//	Type:      "1",
		//	Show:      "0",
		//	OrderNo:   5,
		//	Component: "/k8s/podAdmin/tailLog",
		//	Pid:       7,
		//	Path:      "podTailLog",
		//},
		//
		//{
		//	Name:      "K8sPodWebShell",
		//	Title:     "k8s-pod命令执行",
		//	Icon:      "ant-design:shop-two-tone",
		//	Type:      "1",
		//	Show:      "0",
		//	OrderNo:   5,
		//	Component: "/k8s/podAdmin/webshell",
		//	Pid:       7,
		//	Path:      "podWebShell",
		//},
		{
			Name:      "K8sPodYaml",
			Title:     "k8s-pod-yaml展示",
			Icon:      "ant-design:shop-two-tone",
			Type:      "1",
			Show:      "0",
			OrderNo:   5,
			Component: "/k8s/podAdmin/podYaml",
			Pid:       7,
			Path:      "podYaml",
		},
		{
			Name:      "K8sDeployYaml",
			Title:     "k8s-Deploy-yaml展示",
			Icon:      "ant-design:shop-two-tone",
			Type:      "1",
			Show:      "0",
			OrderNo:   5,
			Component: "/k8s/deployAdmin/deployYaml",
			Pid:       7,
			Path:      "deployYaml",
		},
		{
			Name:      "K8sConfigmapYaml",
			Title:     "k8s-configmap-yaml展示",
			Icon:      "ant-design:shop-two-tone",
			Type:      "1",
			Show:      "0",
			OrderNo:   5,
			Component: "/k8s/configmapAdmin/configmapYaml",
			Pid:       7,
			Path:      "configmapYaml",
		},
		{
			Name:      "K8sServiceYaml",
			Title:     "k8s-service-yaml展示",
			Icon:      "ant-design:shop-two-tone",
			Type:      "1",
			Show:      "0",
			OrderNo:   5,
			Component: "/k8s/serviceAdmin/serviceYaml",
			Pid:       7,
			Path:      "serviceYaml",
		},
		{
			Name:      "K8sDeployManagement",
			Title:     "k8s-deployment管理",
			Icon:      "ant-design:mac-command-filled",
			Type:      "1",
			Show:      "1",
			OrderNo:   6,
			Component: "/k8s/deployAdmin/index",
			Pid:       7,
			Path:      "deployList",
		},

		{
			Name:      "K8sConfigmapManagement",
			Title:     "k8s-Configmap管理",
			Icon:      "ant-design:folder-open-filled",
			Type:      "1",
			Show:      "1",
			OrderNo:   7,
			Component: "/k8s/configmapAdmin/index",
			Pid:       7,
			Path:      "configmapList",
		},

		{
			Name:      "K8sSvcManagement",
			Title:     "k8s-svc管理",
			Icon:      "ant-design:api-filled",
			Type:      "1",
			Show:      "1",
			OrderNo:   7,
			Component: "/k8s/serviceAdmin/index",
			Pid:       7,
			Path:      "serviceList",
		},
	}

	menuK8sPublic = []*Menu{
		{
			Name:      "K8sPodNormalLog",
			Title:     "k8s-pod非tail-log",
			Icon:      "ant-design:shop-two-tone",
			Type:      "1",
			Show:      "0",
			OrderNo:   5,
			Component: "/k8s/podAdmin/normalLog",
			Pid:       7,
			Path:      "podNormalLog",
		},

		{
			Name:      "K8sPodTailLog",
			Title:     "k8s-pod-ws-tail-log",
			Icon:      "ant-design:shop-two-tone",
			Type:      "1",
			Show:      "0",
			OrderNo:   5,
			Component: "/k8s/podAdmin/tailLog",
			Pid:       7,
			Path:      "podTailLog",
		},

		{
			Name:      "K8sPodWebShell",
			Title:     "k8s-pod命令执行",
			Icon:      "ant-design:shop-two-tone",
			Type:      "1",
			Show:      "0",
			OrderNo:   5,
			Component: "/k8s/podAdmin/webshell",
			Pid:       7,
			Path:      "podWebShell",
		},
	}

	menuK8sApp = []*Menu{
		{
			Name:      "K8sProjectsManagement",
			Title:     "k8s项目管理",
			Icon:      "ant-design:project-filled",
			Type:      "1",
			Show:      "1",
			OrderNo:   1,
			Component: "/k8sApplication/project/index",
			Pid:       8,
			Path:      "project",
		},
		{
			Name:      "K8sApplicationsManagement",
			Title:     "k8s应用管理",
			Icon:      "ant-design:apple-filled",
			Type:      "1",
			Show:      "1",
			OrderNo:   2,
			Component: "/k8sApplication/application/index",
			Pid:       8,
			Path:      "application",
		},
		{
			Name:      "K8sApplicationsEditor",
			Title:     "k8s应用编辑",
			Icon:      "ant-design:apple-filled",
			Type:      "1",
			Show:      "0",
			OrderNo:   2,
			Component: "/k8sApplication/application/editor",
			Pid:       8,
			Path:      "editor",
		},
		{
			Name:      "K8sInstancesManagement",
			Title:     "k8s实例管理",
			Icon:      "ant-design:codepen-square-filled",
			Type:      "1",
			Show:      "1",
			OrderNo:   3,
			Component: "/k8sApplication/instance/index",
			Pid:       8,
			Path:      "instance",
		},
		{
			Name:      "K8sCronjobManagement",
			Title:     "k8s计划任务管理",
			Icon:      "ant-design:schedule-filled",
			Type:      "1",
			Show:      "1",
			OrderNo:   4,
			Component: "/k8sApplication/cronjob/index",
			Pid:       8,
			Path:      "cronjob",
		},

		{
			Name:      "K8sInstancesEditor",
			Title:     "k8s实例编辑",
			Icon:      "ant-design:apple-filled",
			Type:      "1",
			Show:      "0",
			OrderNo:   2,
			Component: "/k8sApplication/instance/editor",
			Pid:       8,
			Path:      "instanceEditor",
		},
		{
			Name:      "K8sInstancesLogExec",
			Title:     "k8s实例日志和exec",
			Icon:      "ant-design:apple-filled",
			Type:      "1",
			Show:      "0",
			OrderNo:   2,
			Component: "/k8sApplication/instance/logExec",
			Pid:       8,
			Path:      "instanceLogExec",
		},

		{
			Name:      "K8sCronjobsEditor",
			Title:     "k8s计划任务编辑",
			Icon:      "ant-design:apple-filled",
			Type:      "1",
			Show:      "0",
			OrderNo:   2,
			Component: "/k8sApplication/cronjob/editor",
			Pid:       8,
			Path:      "cronjobEditor",
		},
	}
	menuCicd = []*Menu{
		{
			Name:      "CicdWorkOrderManagement",
			Title:     "cicd工单列表",
			Icon:      "ant-design:funnel-plot-filled",
			Type:      "1",
			Show:      "1",
			OrderNo:   1,
			Component: "/cicd/workorder/index",
			Pid:       9,
			Path:      "orderList",
		},
		{
			Name:      "CicdWorkOrderDetail",
			Title:     "cicd发布单详情",
			Icon:      "ant-design:funnel-plot-filled",
			Type:      "1",
			Show:      "0",
			OrderNo:   1,
			Component: "/cicd/workorder/detail",
			Pid:       9,
			Path:      "orderDetail",
		},
	}
	menuRoleSuper     = []*Menu{}
	menuRoleOps       = []*Menu{}
	menuRoleRebot     = []*Menu{}
	menuRoleK8sAdmin  = []*Menu{}
	menuRoleK8sPublic = []*Menu{}

	menus        = []*Menu{}
	roleSuper    = &Role{}
	roleOps      = &Role{}
	roleK8sAdmin = &Role{}

	roleNoLogin = &Role{}

	// 读取所有 并有写部分的权限
	apiFathers = []*Api{
		{
			Path:   "/api/*",
			Method: "ALL",
			Title:  "所有-写操作",
			Type:   "0",
		},
		{
			Path:   "/api/*",
			Method: "GET",
			Title:  ApiTitleAllRead,
			Type:   "0",
		},

		{
			Path:   "/api/system/*",
			Method: "ALL",
			Title:  "系统管理-写操作",
			Type:   "0",
		},
		{
			Path:   "/api/system/*",
			Method: "GET",
			Title:  "系统管理-读操作",
			Type:   "0",
		},
		{
			Path:   "/api/stree/*",
			Method: "ALL",
			Title:  "服务树-写操作",
			Type:   "0",
		},
		{
			Path:   "/api/stree/*",
			Method: "GET",
			Title:  "服务树-读操作",
			Type:   "0",
		},
		{
			Path:   "/api/workorder/*",
			Method: "ALL",
			Title:  "工单管理-写操作",
			Type:   "0",
		},
		{
			Path:   "/api/workorder/*",
			Method: "GET",
			Title:  "工单管理-读操作",
			Type:   "0",
		},
		{
			Path:   "/api/jobexec/*",
			Method: "ALL",
			Title:  "任务执行中心-写操作",
			Type:   "0",
		},
		{
			Path:   "/api/jobexec/*",
			Method: "GET",
			Title:  "任务执行中心-读操作",
			Type:   "0",
		},
		{
			Path:   "/api/monitor/*",
			Method: "ALL",
			Title:  "Prometheus监控-写操作",
			Type:   "0",
		},
		{
			Path:   "/api/monitor/*",
			Method: "GET",
			Title:  "Prometheus监控-读操作",
			Type:   "0",
		},
		{
			Path:   "/api/k8s/*",
			Method: "ALL",
			Title:  ApiTitleK8sAdminWrite,
			Type:   "0",
		},
		{
			Path:   "/api/k8s/*",
			Method: "GET",
			Title:  "k8s多集群-读操作",
			Type:   "0",
		},
		{
			Path:   "/api/k8sApp/*",
			Method: "ALL",
			Title:  ApiTitleK8sAppWrite,
			Type:   "0",
		},
	}

	apiK8sAdmins        = []*Api{}
	apiSystemCommonRead = []*Api{
		{
			Path:   "/api/system/menu",
			Method: "GET",
			Title:  "系统管理-菜单相关-读操作",
			Type:   "1",
		},
		{
			Path:   "/api/system/getMenuListAll",
			Method: "GET",
			Pid:    1,
			Title:  "系统管理-获取全量菜单",
			Type:   "1",
		},
		{
			Path:   "/api/system/getMenuList",
			Method: "GET",
			Title:  "系统管理-根据用户获取菜单",
			Type:   "1",
		},
		{
			Path:   "/api/system/account",
			Method: "GET",
			Title:  "系统管理-用户相关-读操作",
			Type:   "1",
		},
		{
			Path:   "/api/getUserInfo",
			Method: "GET",
			Title:  "获取用户信息",
			Type:   "1",
		},
		{
			Path:   "/api/getPermCode",
			Method: "GET",
			Title:  "获取用户code",
			Type:   "1",
		},
		{
			Path:   "/api/system/getAccountList",
			Method: "GET",
			Title:  "获取用户列表",
			Type:   "1",
		},
	}

	apiK8sApp = []*Api{}

	apis = []*Api{}

	feishuUserIds = []string{
		"6d31gdf4",
		"38g18781",
	}

	u1 = User{
		Username:     "admin",
		Password:     "123456",
		RealName:     "花海",
		Desc:         "",
		Mobile:       "158xxxxxxxx",
		HomePath:     "/system/account",
		FeiShuUserId: "6d31gdf4",
		Enable:       1,
	}

	u2 = User{
		Username:     "test",
		Password:     "123456",
		Mobile:       "15810947075",
		RealName:     "二狗",
		Desc:         "",
		FeiShuUserId: "38g18781",
		HomePath:     "/system/account",
		Enable:       1,
	}

	u3 = User{
		Username:     "auto_order_robot",
		Password:     "123456",
		RealName:     "自动工单执行机器人",
		Mobile:       "15810947075",
		FeiShuUserId: feishuUserIds[common.Frn(len(feishuUserIds)-1)],
		Desc:         "",
		HomePath:     "/system/account",
		Enable:       1,
	}

	u4 = User{
		Username:     "k8s_admin_01",
		Password:     "123456",
		RealName:     "k8s管理员",
		Mobile:       "15810947075",
		FeiShuUserId: feishuUserIds[common.Frn(len(feishuUserIds)-1)],
		Desc:         "",
		HomePath:     "/k8s/cluster",
		Enable:       1,
	}
	uSaCicd = User{
		Model:               Model{},
		Username:            "cicd01",
		AccountType:         2,
		ServiceAccountToken: "abcd",
	}
)

func init() {
	// 超级管理员
	menuRoleSuper = append(menuRoleSuper, menuFathers...)
	menuRoleSuper = append(menuRoleSuper, menuSystem...)
	menuRoleSuper = append(menuRoleSuper, menuFront...)
	menuRoleSuper = append(menuRoleSuper, menuServiceTree...)
	menuRoleSuper = append(menuRoleSuper, menuWorkOrder...)
	menuRoleSuper = append(menuRoleSuper, menuJobExec...)
	menuRoleSuper = append(menuRoleSuper, menuPrometheusMonitor...)
	menuRoleSuper = append(menuRoleSuper, menuK8sClusters...)
	menuRoleSuper = append(menuRoleSuper, menuK8sPublic...)
	menuRoleSuper = append(menuRoleSuper, menuK8sApp...)
	menuRoleSuper = append(menuRoleSuper, menuCicd...)

	// 普通运维
	menuRoleOps = append(menuRoleOps, menuServiceTree...)
	menuRoleOps = append(menuRoleOps, menuWorkOrder...)
	menuRoleOps = append(menuRoleOps, menuJobExec...)
	menuRoleOps = append(menuRoleOps, menuPrometheusMonitor...)
	menuRoleOps = append(menuRoleOps, menuK8sApp...)
	menuRoleOps = append(menuRoleOps, menuCicd...)
	// 让普通运维添加
	menuRoleOps = append(menuRoleOps, menuK8sPublic...)

	menuRoleK8sAdmin = append(menuRoleK8sAdmin, menuServiceTree...)
	menuRoleK8sAdmin = append(menuRoleK8sAdmin, menuWorkOrder...)
	menuRoleK8sAdmin = append(menuRoleK8sAdmin, menuK8sClusters...)

	roleSuper = &Role{
		RoleName:  "超级管理员",
		RoleValue: "super",
		Menus:     menuRoleSuper,
		Apis:      apiFathers,
	}
	roleOps = &Role{
		RoleName:  "普通运维",
		RoleValue: "ops",
		Menus:     menuRoleOps,
	}

	roleNoLogin = &Role{
		RoleName:  "后台机器人",
		RoleValue: "bot_super",
		Menus:     menuRoleRebot,
	}
	roleK8sAdmin = &Role{
		RoleName:  "k8s集群管理员",
		RoleValue: "k8s_admin",
		Menus:     menuRoleK8sAdmin,
	}

	u1.Roles = []*Role{roleSuper}
	u2.Roles = []*Role{roleOps}
	u3.Roles = []*Role{roleNoLogin}
	u4.Roles = []*Role{roleK8sAdmin}

	tmp := []*Api{}
	tmp = append(tmp, apiFathers...)
	tmp = append(tmp, apiSystemCommonRead...)
	tmp = append(tmp, apis...)
	apis = tmp
	//
	//tmp1 := []*Api{}
	//tmp1 = append(tmp1, apiFathers...)
	//tmp1 = append(tmp1, apiSystemCommonRead...)
	//apiSystemCommonRead = tmp1
	//
	//tmp2 := []*Api{}
	//tmp2 = append(tmp2, apiSystemCommonRead...)
	//tmp2 = append(tmp2, apiK8sAdmins...)
	//apiK8sAdmins = tmp2

}

func MockBasicData(sc *config.ServerConfig) {

	sc.Logger.Info("开始创建固定用户")
	u1.Password = common.BcryptHash(u1.Password)
	u2.Password = common.BcryptHash(u2.Password)
	u3.Password = common.BcryptHash(u3.Password)
	u4.Password = common.BcryptHash(u4.Password)

	users := []*User{
		&u1,
		&u2,
		&u3,
		&u4,
		&uSaCicd,
	}
	for _, user := range users {
		user := user
		err := user.FirstOrCreate()
		if err != nil {
			sc.Logger.Error(fmt.Sprintf("模拟用户注册失败:%v", user.Username), zap.String("错误", err.Error()))
		}
	}
	sc.Logger.Info("结束创建固定用户")

	sc.Logger.Info("开始创建mock用户")
	num := 5
	for i := 0; i < num; i++ {
		u := User{
			Username:     fmt.Sprintf("mock-user-%v", i),
			FeiShuUserId: feishuUserIds[common.Frn(len(feishuUserIds)-1)],
			Password:     "123456",
			RealName:     fmt.Sprintf("mock-real-%v", i),
			HomePath:     "/system/account",
			Enable:       1,
		}
		err := u.FirstOrCreate()
		if err != nil {
			sc.Logger.Error(fmt.Sprintf("模拟用户注册失败:%v", u.Username), zap.Error(err))
		}

	}
	sc.Logger.Info("结束创建mock用户")

	// 新增apis
	//err = Db.Create(apis).Error
	//sc.Logger.Info("创建api结果", zap.Any("err", err))

	sc.Logger.Info("开始更新role的api权限")
	// 查询一下 super这个role
	dbRoleSuper, _ := GetRoleByRoleValue("super")
	dbRoleSuper.Apis = apis
	sc.Logger.Info("super更新api开始")
	err := dbRoleSuper.UpdateApisNoUpdateSelf(apis, sc)
	if err != nil {
		sc.Logger.Error("super更新api出错", zap.Any("err", err))

	}
	sc.Logger.Info("super更新api结束")

	// 查询一下 super这个role
	dbRoleOps, _ := GetRoleByRoleValue("ops")

	apiAllRead, _ := GetApiByTitle(ApiTitleAllRead)
	apiK8sAdminWrite, _ := GetApiByTitle(ApiTitleK8sAdminWrite)
	apiK8sAppWrite, _ := GetApiByTitle(ApiTitleK8sAppWrite)

	// 普通运维有什么权限：所有的读 + app的写
	err = dbRoleOps.UpdateApis([]*Api{apiAllRead, apiK8sAppWrite}, sc)
	sc.Logger.Info("ops更新api结果", zap.Any("err", err))

	// k8s_admin 是不是要 所有只读+ k8sadmin
	dbRoleK8sAdmin, _ := GetRoleByRoleValue("k8s_admin")
	err = dbRoleK8sAdmin.UpdateApis([]*Api{apiAllRead, apiK8sAdminWrite}, sc)
	sc.Logger.Info("k8s_admin更新api结果", zap.Any("err", err))

	//Db.Save(&u1)
	sc.Logger.Info("模拟用户注册成功")

}
